package com.crm.dataReceive.controller;

import com.crm.custinfo.service.IHitPackageService;
import com.crm.dataReceive.domain.GetStart;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.constant.ConfigConstant;
import com.ruoyi.system.service.ISysConfigService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/manageDataExchange")
public class AccessToDataInformationController {
    public static final org.slf4j.Logger logger = LoggerFactory.getLogger("AccessToDataInformation");
    @Autowired
    private IHitPackageService hitPackageService;
    @Autowired
    private ISysConfigService baseSysConfigService;
    @Anonymous
    @PostMapping("/getMd5List/tenant/{tenantId}")
    public Map<String, Object> getMd5List(@RequestBody GetStart checkApi) {
        String allowedChannel = baseSysConfigService.getItemValueByItemKey(ConfigConstant.MEDIA_ALLOWED_TO_CHANNEL, "");
        Map<String, Object> map = new HashMap<>();
        if (checkApi == null) {
            map.put("code", 500);
            map.put("msg", "请求包数据为空");
            return map;
        }
        if (!allowedChannel.contains(checkApi.getChannelSource())) {
            map.put("code", 404);
            map.put("msg", "请求异常");
            return map;
        }
        if(checkApi.getChannelSource()==null||checkApi.getChannelSource().equals("")){
            map.put("code", 500);
            map.put("msg", "业务码为空");
            return map;
        }
        String secretKey = baseSysConfigService.getItemValueByItemKey(checkApi.getChannelSource());
        if (!checkApi.getSecretKey().equals(secretKey)) {
            map.put("code", 500);
            map.put("msg", "请求异常");
            return map;
        }
        List<Map<String,Object>> list1= hitPackageService.selectHitPackageMd5();
        List<String> mobileMd5List = list1.stream()
                .map(m -> (String) m.get("mobile_md5"))
                .collect(Collectors.toList());
        map.put("code", 200);
        map.put("msg", "获取成功");
        map.put("data",mobileMd5List);
        return map;
    }

}
